package cate.game.play.buff.h;


import cate.game.play.base.HpCfg;
import cate.game.play.buff.BuffHandler;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.proce.action.ctx.ActionCtx;
import cate.game.play.proce.result.BuffAnounceResult;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;

@NoteClass("回合治疗结算BH")
public class 回合治疗结算BH extends BuffHandler {

    @NoteField("血量配置")
    private HpCfg cfg;

    @NoteField("回合开始生效")
    private boolean roundBegin;

    @NoteField("回合结束生效")
    private boolean roundEnd;

    //血量配置=1:1:1000&回合开始=0&回合结束=1
    @Override
    public void parse(String code) {
        PlayCfgArgs args = new PlayCfgArgs(code);
        cfg = new HpCfg(args);
        roundBegin = args.getBoolean("回合开始", false);
        roundEnd = args.getBoolean("回合结束", false);
    }

    @Override
    public void onRoundBegin(ActionCtx action) {
        if (roundBegin) {
            settle(action);
        }
    }

    @Override
    public void onRoundEnd(ActionCtx action) {
        if (roundEnd) {
            settle(action);
        }
    }

    private void settle(ActionCtx action) {
        if (buff.owner.isDead()) {
            return;
        }
        double total = cfg.settle(buff.caster, buff.owner);
        if (total <= 0) {
            return;
        }
        buff.owner.attr.buffHeal(action, buff.caster, total);
        action.addResult(new BuffAnounceResult().pidSet(buff.owner).buffTidSet(buff.tid));
    }
}
